package com.jlkf.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jlkf.pojo.TblCourse;
import com.jlkf.service.PlatformService;
import com.platform.server.response.response.pojo.ReturnData;
import com.platform.server.util.StringTools;

@Controller
@RequestMapping("/platform")
public class PlatformController {
	
	@Autowired
	private PlatformService platformService;
	
	/**
	 * 查看平台费用折扣
	 */
	@ResponseBody
	@RequestMapping("/selectPlatformDiscount")
	public Object selectPlatformDiscount(){
		int flag = platformService.selectPlatformDiscount();
		return new ReturnData(flag,200,"平台折扣");
	}
	
	/**
	 * 修改平台费用折扣
	 */
	@ResponseBody
	@RequestMapping("updatePlatformDiscount")
	public Object updatePlatformDiscount(Integer discount){
		int flag = platformService.updatePlatformDiscount(discount);
		return new ReturnData(flag,200,"成功");
	}
	
	/**
	 * 查看平台活动
	 */
	@ResponseBody
	@RequestMapping("/selectPlatformActivity")
	public Object selectPlatformActivity(){
		Map<String, Object> map = platformService.selectPlatformActivity();
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("result",map);
		modelAndView.setViewName("jsp/platformManager/updatePlatformActivity");
		return modelAndView;
	}
	
	/**
	 * 修改平台活动
	 */
	@ResponseBody
	@RequestMapping("updatePlatformActivity")
	public Object updatePlatformActivity(String cover_image,String cover_headline,String cover_title,String cover_content,String about_headline,String about_image,String about_img1,String about_img2,
			String about_img3,String about_img4,String about_content,String course_headline,String course_title1,String course_content1,String course_title2,String course_content2,
			String course_title3,String course_content3,String course_title4,String course_content4,String teacher_headline,String teacher_image,String teacher_name,String teacher_content,
			String contact_address,String contact_phone,String contact_email){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("cover_image", cover_image);
		map.put("cover_headline", cover_headline);
		map.put("cover_title", cover_title);
		map.put("cover_content", cover_content);
		map.put("about_headline", about_headline);
		map.put("about_image", about_image);
		map.put("about_img1", about_img1);
		map.put("about_img2", about_img2);
		map.put("about_img3", about_img3);
		map.put("about_img4", about_img4);
		map.put("about_content", about_content);
		map.put("course_headline", course_headline);
		map.put("course_title1", course_title1);
		map.put("course_content1", course_content1);
		map.put("course_title2", course_title2);
		map.put("course_content2", course_content2);
		map.put("course_title3", course_title3);
		map.put("course_content3", course_content3);
		map.put("course_title4", course_title4);
		map.put("course_content4", course_content4);
		map.put("teacher_headline", teacher_headline);
		map.put("teacher_image", teacher_image);
		map.put("teacher_name", teacher_name);
		map.put("teacher_content", teacher_content);
		map.put("contact_address", contact_address);
		map.put("contact_phone", contact_phone);
		map.put("contact_email", contact_email);
		int flag = platformService.updatePlatformActivity(map);
		return new ReturnData(flag,200,"成功");
	}
	
	/**
	 * 平台活动列表
	 */
	@ResponseBody
	@RequestMapping("/selectPlatformList")
	public ReturnData selectPlatformList(String startTime,String endTime,Integer pageNumber,Integer pageSize){
		Map<String, Object> map = new HashMap<String,Object>();
		if(!StringTools.isEmpty(startTime)){
			map.put("startTime", startTime);
		}
		if(!StringTools.isEmpty(endTime)){
			map.put("endTime", endTime);
		}
		PageHelper.startPage(pageNumber, pageSize);
		List<Map<String,Object>> list = platformService.selectPlatformList(map);
		PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
		return new ReturnData(list,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"平台活动列表");
	}
	
}
